#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const  int maxn=1e5+10;
ll sz[maxn];
ll n,m;
ll l,r,ans;
bool pd(ll x)
{
    ll sm=0,js=1;
    for(int i=1;i<=n;++i)
    {
        if(sm+sz[i]>x)
        {
            js++;
            sm=0;
        }
        sm+=sz[i];
    }
    return js<=m;
}
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;++i)
    {
        scanf("%lld",sz+i);
        r+=sz[i];l=max(l,sz[i]);
    }

    while(l<=r) //二分查找，直到找到最合适的值
    {
        ll mid=(l+r)>>1;
        if(pd(mid))ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans;
    return 0;
}